package com.cx330;

import org.junit.Test;

import java.util.LinkedList;
import java.util.Stack;

public class Example62 {
    @Test
    public void test1() {
        System.out.println("进栈：java,hello,cx330");
        Stack<String> stack = new Stack<>();;
        stack.push("java");
        stack.push("hello");
        stack.push("cx330");
        System.out.println("栈顶元素：" + stack.peek());
        System.out.println("栈顶元素：" + stack.peek());
        System.out.println("出栈：");
        while (!stack.isEmpty()) {
            System.out.println(stack.pop());
        }
    }

    @Test
    public void test2() {
        System.out.println("进栈：java,hello,cx330");
        LinkedList<String> stack = new LinkedList<>();
        stack.push("java");
        stack.push("hello");
        stack.push("cx330");
        System.out.println("栈顶元素：" + stack.peek());
        System.out.println("栈顶元素：" + stack.peek());
        System.out.println("出栈：");
        while (!stack.isEmpty()) {
            System.out.println(stack.pop());
        }
    }

    @Test
    public void test3() {
        System.out.println("进队：java,hello,cx330");
        LinkedList<String> queue = new LinkedList<>();
        queue.addLast("java");
        queue.addLast("hello");
        queue.addLast("cx330");
        System.out.println("队头元素：" + queue.getFirst());
        System.out.println("队头元素：" + queue.getFirst());
        System.out.println("出队列：");
        while (!queue.isEmpty()) {
            System.out.println(queue.removeFirst());
        }
//        System.out.println(queue.removeFirst()); // 异常
    }

    @Test
    public void test4() {
        System.out.println("进队：java,hello,cx330");
        LinkedList<String> queue = new LinkedList<>();
        queue.offerLast("java");
        queue.offerLast("hello");
        queue.offerLast("cx330");
        System.out.println("队头元素：" + queue.peekLast());
        System.out.println("队头元素：" + queue.peekLast());
        System.out.println("出队列：");
        while (!queue.isEmpty()) {
            System.out.println(queue.pollFirst());
        }
        System.out.println(queue.pollFirst());
    }
}
